/**
 * 作者: wgx
 * 日期: 2024-10-15 14:05:59
 * 备注: 技能配置表
 */
package com.motu.monstercity.server.game.commondata.skill;
import com.motu.monstercity.server.game.base.CommonUtils;
import com.motu.monstercity.server.game.logic.PartnerManager;
import com.motu.monstercity.server.game.logic.RewardItem;
import com.motu.monstercity.server.game.logic.SkillManager;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

import java.util.ArrayList;
import java.util.List;

public class Skill extends SkillModel {
    public Skill(JsonObject obj) {
        super(obj);
    }

    // 获取技能升级需要消耗的道具
    public List<RewardItem> takeLevelUpItems(int level) {
        List<RewardItem> result = new ArrayList<>();
        JsonArray itemIds = CommonUtils.strToJsonArray(getUpgradeItem());//itemid列表
        JsonArray upgradeTypeList = CommonUtils.strToJsonArray(getUpgradeType());
        for (int i=0; i<itemIds.size(); i++) {
            int itemId = itemIds.getInteger(i);
            long itemNum = SkillManager.getSkillLeveUpConsume(upgradeTypeList.getInteger(i), level);
            RewardItem rewardItem = new RewardItem(itemId, itemNum);
            result.add(rewardItem);
        }
        return result;
    }

    // 技能升级需要消耗的道具数量，消耗道具,消耗类型只支持单一
    public long takeLevelUpItemNum(int level) {
        try {
            int upgradeType = Integer.parseInt(getUpgradeType());
            return SkillManager.getSkillLeveUpConsume(upgradeType, level);
        } catch (Exception e) {
            return 0L;
        }
    }

    // 技能总的加成,会有递增的增量，
    public int countTotalAdd(int level) {
        if (level == 0) {
            return 0;
        }
        int baseValue = getBaseValue() > 0 ? getBaseValue() : getBaseValuePer();// 是用固定值还是百分比
        int addValue = getBaseValue() > 0 ? getLevelUpAdd() : getLevelUpAddPer();

        if (level == 1) {
            return baseValue;
        } else {
            int totalAdd = 0;//
            for (int i=2;i<=level;i++) {
                int add = addValue + getIncremValue() * (i-1);
                totalAdd += add;
            }
            return baseValue + totalAdd;
        }
    }

    // 每升1级，增加的加成值
    public int takeLevelUpDiff(int newLevel) {
        int newAdd = countTotalAdd(newLevel);// 新一级的加成
        int lastAdd = countTotalAdd(newLevel - 1);// 上一级的加成
        return newAdd - lastAdd;
    }
}
